<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function copy_o(obj) {
        var newobj = new Object();
        for (var key in obj) {
          //对象添加 obj.新键名=值；obj[key]=值 当该键名不存在时视作添加 存在时后面的值覆盖原有值
          newobj[key] = obj[key];
        }
        return newobj;
      }
      var obj = {
        name: "wqz",
        obj1: {
          myname: "李四",
          age: 20,
        },
      };
      var obj1=copy_o(obj)
      console.log(obj1);
      obj1.obj1.name="lulu"
      console.log(obj);
    </script>
  </body>
</html>
